package com.example.workflow.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.workflow.common.R;
import com.example.workflow.dto.EmployeeFormDto;
import com.example.workflow.entity.Employee;
import com.example.workflow.service.EmployeeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/auth/employee")
public class EmployeeController {
    private final EmployeeService employeeService;;



    /**
     * 新建员工*/
    @PostMapping("/add")
    public R addEmployee(@RequestBody EmployeeFormDto employee) {
        if (employee == null) {
            return R.error("员工信息不能为空");
        }
        if (employee.getNum() == null) {
            return R.error("员工工号不能为空");
        }
        if (employee.getName() == null) {
            return R.error("员工姓名不能为空");
        }
        if (employee.getBirthday() == null) {
            return R.error("员工出生日期不嫩为空");
        }
        if (employee.getIdNum() == null) {
            return R.error("员工身份证不能为空");
        }
        if (employee.getDeptId() == null) {
            return R.error("员工部门不能为空");
        }
        if (employee.getPostId() == null || employee.getPostId().isEmpty()) {
            return R.error("员工岗位不能为空");
        }
        if (employee.getGrade() == null) {
            return R.error("员工级别不能为空");
        }
        if (employee.getEmail() == null) {
            return R.error("员工邮箱不嫩为空");
        }
        if (employee.getPhoneNum1() == null) {
            return R.error("员工联系电话1不能为空");
        }
        return employeeService.addEmployee(employee);

    }


    /**
     * 根据员工id查询全部的信息*/

    @GetMapping("/info")
    public R info(List<Long> id) {
        if (id == null) {
            return R.error("id不能为空");
        }
        return employeeService.getEmployeeById(id);
    }

    /**
     *更新员工*/
    @PutMapping("/update")
    public R updateEmployee(@RequestBody EmployeeFormDto employeeFormDto) {
        if (employeeService == null) {
            return R.error("信息不能为空");
        }
        return employeeService.updateEmployee(employeeFormDto);
    }

    /**
     * 删除员工*/
    @DeleteMapping("/delete")
    public R deleteEmployeeById(List<Long> ids) {
        if (ids == null) {
            return R.error("id 不能为空");
        }
        return employeeService.deleteEmployeeById(ids);
    }

    /**
     * 查询员工信息  模糊查询*/
    @GetMapping("/like")
    public R like(@RequestBody EmployeeFormDto employeeFormDto) {
            if (employeeFormDto == null) {
                return R.error("信息不能为空");
            }
            return employeeService.lookByLike(employeeFormDto);
    }

    /**
     * 查询全部员工信息*/
    @GetMapping("/list")
    public R page(Integer page, Integer pageSize) {
        Page<Employee> employeePage = new Page<>(page, pageSize);
        employeeService.page(employeePage);
        return R.success(employeePage);
    }
}
